home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 378 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: news.mel.aone.net.au!usenet
  2. From: clyde@hitech.com.au (Clyde Smith-Stubbs)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HP UX 10.0 C programming
  5. Date: Thu, 04 Jan 1996 22:28:44 GMT
  6. Organization: HI-TECH Software
  7. Message-ID: <30ec5378.1252135360@news.bne.aone.net.au>
  8. References: <4cfje3$qk@nn.fast.net>
  9. Reply-To: clyde@hitech.com.au
  10. NNTP-Posting-Host: skyhawk.hitech.com.au
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. On 4 Jan 1996 04:01:07 GMT, "Chad R. Laity" <wick@pop.fast.net> wrote:
  14.  
  15. >             (2) Why do I get an error on this cut down program listed
  16. >                 below when I compile it on an HP 9000 K200 with HP UX 10.0
  17. >                 and I do not get an error with our Intergraph server?
  18.  
  19. >#include <stdio.h>
  20. >#include <sys/stat.h>
  21. >
  22. >main()
  23. >{
  24. >int i;
  25. >int stat(const char *path, struct stat *buf);    /****<<<--- GET RID OF THIS LINE ******/
  26. >
  27. >i = stat("/usr2/test/testfile", &buf);           /* line 15 */
  28. >
  29. >}
  30.  
  31. You should get rid of the declaration of stat() that you have embedded
  32. inside main(). Firstly, putting extern declarations inside functions
  33. is invariably a Bad Idea in C, even though it's technically legal. It
  34. uses the scoping rules of C to hide information from the compiler.
  35.  
  36. Secondly, stat() is a system-defined function, and it has its
  37. prototype in <sys/stat.h> already - you should not redeclare it. Doing
  38. so is non-portable (as you just found out :-).
  39.  
  40. Thirdly, I don't see a declaration for buf anywhere - add the line:
  41.  
  42.     struct stat    buf;
  43.  
  44. just inside the opening brace of main(). That should fix it.
  45.  
  46. ----
  47.  Clyde Smith-Stubbs       | HI-TECH Software,       | Voice: +61 7 3300 5011
  48.  clyde@hitech.com.au      | P.O. Box 103, Alderley, | Fax:   +61 7 3300 5246
  49. http://www.hitech.com.au  | QLD, 4051, AUSTRALIA.   | BBS:   +61 7 3300 5235
  50. ----------------------------------------------------------------------------
  51. FREE! Download our shareware (FREE for noncommercial use) MS-DOS C Compiler!
  52.              Point your Web browser at http://www.hitech.com.au/
  53.